package com.xxgc.eow.service.impl;

import com.github.pagehelper.PageHelper;
import com.xxgc.eow.entity.CollectSecondaryCommentSeconday;
import com.xxgc.eow.entity.Collectsecondarycomment;
import com.xxgc.eow.mapper.CollectsecondarycommentMapper;
import com.xxgc.eow.service.ICollectsecondarycommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 收藏的二级评论表 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-24
 */
@Service
public class CollectsecondarycommentServiceImpl extends ServiceImpl<CollectsecondarycommentMapper, Collectsecondarycomment> implements ICollectsecondarycommentService {

    @Resource
    private CollectsecondarycommentMapper collectsecondarycommentMapper;

    @Override
    public List<Collectsecondarycomment> getCollectsecondarycommentsByUserId(Integer userId) {
        return collectsecondarycommentMapper.selectAllByUserId(userId);
    }

    @Override
    public int insertLikeComment(CollectSecondaryCommentSeconday collectSecondaryCommentSeconday) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        collectSecondaryCommentSeconday.setCreateTime(localDateTime);
        return collectsecondarycommentMapper.insertLikeComment(collectSecondaryCommentSeconday);
    }

    @Override
    public Integer getCommentLikeById(int secondaryCommentId) {
        return collectsecondarycommentMapper.getLikeNumByCommentId(secondaryCommentId);
    }

    @Override
    public int updateCommentLike(int secondaryCommentId, int collectNum) {
        return collectsecondarycommentMapper.updateCommentLike(secondaryCommentId,collectNum);
    }

    @Override
    public int delCommentLike(CollectSecondaryCommentSeconday collectSecondaryCommentSeconday) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        collectSecondaryCommentSeconday.setDestroyTime(localDateTime);
        return collectsecondarycommentMapper.delLikeComment(collectSecondaryCommentSeconday);
    }

    @Override
    public CollectSecondaryCommentSeconday selectDataTf(CollectSecondaryCommentSeconday collectSecondaryCommentSeconday) {
        return collectsecondarycommentMapper.selectDataTf(collectSecondaryCommentSeconday);
    }

    @Override
    public List<CollectSecondaryCommentSeconday> selectAll(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return collectsecondarycommentMapper.selectAll();
    }
}
